import java.util.HashMap;

/**
 * create by Sun
 * 2018/8/31
 */
public class zuichuangzichuan {
    public static int lengthOfLongestSubstring(String s) {
        HashMap<Character,Integer> map=new HashMap<Character, Integer>();
        int begin=0;
        int max=0;
        int first=-1;
        for (int i=0;i<s.length();i++){
            if(map.containsKey(s.charAt(i))){
                begin=Math.max(map.get(s.charAt(i))+1,begin);
            }
            if(max<i-begin+1){
                max=i-begin+1;
                first=begin;

            }
            map.put(s.charAt(i),i);
        }
       // System.out.println(first);
        return max;
    }
    public static void main(String[] args) {

        System.out.println( lengthOfLongestSubstring("bcabcdbb"));
    }
}
